package com.pay.ioopos.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aggregate.pay.sanstar.SanstarApiFactory;
import com.aggregate.pay.sanstar.bean.Result;
import com.aggregate.pay.sanstar.bean.StatisticsOverviewResult;
import com.aggregate.pay.sanstar.support.Client;
import com.pay.ioopos.ApiFactory;
import com.pay.ioopos.BindState;
import com.pay.ioopos.R;

public class StatisticsOverviewFragment extends AbstractNetworkFragment implements BindState {

    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return view = inflater.inflate(R.layout.fragment_statistics_overview, container, false);
    }

    @Override
    protected void execute() throws Exception {

        Client<Void, StatisticsOverviewResult> client = SanstarApiFactory.statisticsOverview(ApiFactory.initApi());

        showLoading();
        Result<StatisticsOverviewResult> apiResult = client.execute(null);
        hideLoading();

        if (apiResult.getStatus() != Result.Status.OK) {
            onError("[" + apiResult.getCode() + "]" + apiResult.getMessage());
            return;
        }

        StatisticsOverviewResult overview = apiResult.getData();
        handle(() -> {
            LinearLayout mainLinerLayout = view.findViewById(R.id.stat_container);
            for (int i = 0; i < overview.size(); i++) {
                TextView textView = new TextView(getContext());
                textView.setTextSize(30);
                /*
                if (i == 0) {
                    textView.setTextSize(35);
                } else {
                    textView.setTextSize(30);
                }
                */
                textView.setText(overview.get(i));
                mainLinerLayout.addView(textView);
            }
        });

    }

}
